var $ = require('../../utils/Ajax.js');
function Tab(that){
  $.Ajax("api/x_order", "POST", {}, function (res) {
    console.log(res)
    that.setData({
      Order: res.d.order_list,
      Order1: res.d.order_list1,
      Order2: res.d.order_list2
    })
  });
}

Page({
  data: {
    tabs: ["未使用", "已使用", "已退订"],
    activeIndex: 0,
    Order: null,
    Order1: null,
    Order2: null,
    // 图片地址
    PictureUrl: getApp().PictureUrl
  },
  onLoad: function () {
    wx.setNavigationBarTitle({
      title: "我的订单"
    });
  },
  onShow: function(){
    var Token = wx.getStorageSync('Token');
    if (Token == '' || Token == null) {
      this.setData({
        Order: null
      })
      wx.showToast({
        title: '请重新登录',
        icon: 'success',
        image: '../../images/err.png',
        duration: 1000,
        mask: true
      })
      setTimeout(function(){
        wx.switchTab({
          url: '../My/My',
        })
      },1000)
    } else {
      Tab(this);
    }
  },
  
  // 点击顶部tab栏
  tabClick: function (e) {
    // Tab(this);
    this.setData({
      activeIndex: e.currentTarget.id
    });
  },

  // 点击未使用
  Unused: function (e) {
    var Type = e.currentTarget.dataset.type;
    if (Type == 2){
      wx.showToast({
        title: '活动禁止退款！',
        icon: 'success',
        image: '../../images/err.png',
        duration: 1000
      })
    }else{
      var Id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '../Unused/Unused?Id=' + Id,
      })
    }
  },

  // 点击评价
  Used: function (e) {
    var Id = e.currentTarget.dataset.id;
    var Type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: '../Used/Used?Id=' + Id + "&Type=" + Type,
    })
  },

  // 已经评价过了
  Used_: function () {
    wx.showToast({
      title: '已经评价过咯',
      icon: 'success',
      duration: 1500
    })
  },

  // 点击以退订
  Unsubscribe: function () {
    wx.navigateTo({
      url: '../Unsubscribe/Unsubscribe',
    })
  },

  onPullDownRefresh: function () {
    wx.stopPullDownRefresh()
  }
});